Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

307
Views
axios.post is showing error "Request failed with status code 400" but same data is posted by postman

when i am post same "data-object" with same "url-link" in postman, its working and my data is post successfully in postman. but when hit request through axios, there is accoured error "Request failed with status code 400". and my data is not posting. i tried to pass data object of axios, eg, "JSON.stringify(data)" but its not working and showing error "status 400". plez solve my query....

there is axios error

const Axios = require("axios");
export const uploadImages = (data) => async (dispatch) => {
  dispatch({
    type: "UPLOAD_IMAGES_INIT",
  });
  try {
    const result = await Axios.post("http://localhost:4000/postImages", {
      "id":1,
      "name":"Flare Dress",
      "price":12000,
      "salePrice":20000,
      "discount":10,
      "pictures":[
         "/assets/images/fashion/product/1.jpg",
      ],
      "shortDetails":"Sed ut perspiciatis, unde omnis iste natu",
      "description":"Lorem Ipsum is simply dummy text of",
      "stock":16,
      "new":true,
      "sale":true,
      "category":"women",
      "colors":[
         "yellow",
      ],
      "size":[
         "M",
      ],
      "tags":[
         "nike",
      ],
      "rating":4,
      "variants":[
         {
            "color":"yellow",
            "images":"/assets/images/fashion/product/1.jpg"
         },

      ],
      "newPostImages":[
         {
            "images":"/assets/images/fashion/product/1.jpg"
         },
      ]
   });
  } catch (err) {
    const error = err.message || "Error Upload Images";
    dispatch({
      type: "UPLOAD_IMAGES_FAIL",
      payload: error,
    });
  }
};

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I got an answer to this question. There's a difference in the request structure from Postman and my code (No matter if using fetch or Axios). Yeah, it may happen that the current user does not have permissions for some entity, but in this case it's all about the following:

  • Simple answer: You have to choose cookie auth or basic auth.
  • Basic auth: base64 format for user and password.
  • Cookie auth (I'm using this option): Drupal sets a header with a session cookie when doing the login request (Postman is automatic, but in your code request, you need to include and send the same cookie for a POST or PATCH or whatever needs auth). Don't forget to send your token header also.
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!